package com.xj.demo.string;

public class StringTest5 {
    public static void main(String[] args) {
//        test1();
        test2();
    }

    public static void test1(){
        long start = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < 100000; i++) {
            str += i;
        }
        System.out.println("test1耗时：" + (System.currentTimeMillis() - start) + "ms");
    }
    public static void test2(){
        long start = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder(1000000);
        for (int i = 0; i < 1000000; i++) {
            sb.append(i);
        }
        String str = sb.toString();
        System.out.println("test2耗时：" + (System.currentTimeMillis() - start) + "ms");
    }
}
